export default {
  data(){
    return{
      setHeight: 0,//屏幕的高度
    }
  },
  methods: {
    //手机号*号展示
    phone(data){
      let tel = data;
      let reg = /^(\d{3})\d{4}(\d{4})$/;
      tel = tel.replace(reg, "$1****$2");
      return tel
    },
    //获取本日
    NewDay(){
      let date = new Date();
      this.form.start_time =  this.timeFormat(date)
      this.form.end_time =  this.timeFormatTwo(date)
    },
    //获取本周
    toDay(){
      let date = new Date();
      let today= this.getFirstDayOfWeek(date) //周一
      let laday= this.getFirstWeek(date) //周日
      this.form.start_time = today
      this.form.end_time = laday
    },
    //获取月份
    yearChange(){
      let date = new Date();
      let  firstDayOfMonth = this.getFirstDayOfMonth(date) //本月第一天
      let lasttDayOfMonth= this.getCurrentMonthLast()
      // console.log("本月第一天:"+firstDayOfMonth )
      // console.log("本月最后一天:"+lasttDayOfMonth )
      this.form.start_time = firstDayOfMonth
      this.form.end_time = lasttDayOfMonth
    },
    //获取周一日期
    getFirstDayOfWeek (date) {
      var weekday = date.getDay() || 7; //获取星期几,getDay()返回值是 0（周日） 到 6（周六） 之间的一个整数。0||7为7，即weekday的值为1-7
      date.setDate(date.getDate()-weekday+1);//本周第一天
      return this.timeFormat(date);
    },
    //获取周日日期
    getFirstWeek (date) {
      var weekday = date.getDay() || 7; //获取星期几,getDay()返回值是 0（周日） 到 6（周六） 之间的一个整数。0||7为7，即weekday的值为1-7
      let add = 7 - weekday // 距离本周结束时间
      date.setDate(date.getDate()+add)
      return this.timeFormatTwo(date);
    },

    //获取本月1号
    getFirstDayOfMonth: function (date) {
      date.setDate(1);
      return this.timeFormat(date);
    },
    getFirstMonth: function (date) {
      date.setDate(1);
      return this.timeFormatTwo(date);
    },
    getCurrentMonthLast(){
      var date=new Date();
      var currentMonth=date.getMonth();
      var nextMonth=++currentMonth;
      var nextMonthFirstDay=new Date(date.getFullYear(),nextMonth,1);
      var oneDay=1000*60*60*24;
      var lastTime = new Date(nextMonthFirstDay-oneDay);
      var month = parseInt(lastTime.getMonth()+1);
      var day = lastTime.getDate();
      if (month < 10&& !month.toString().includes('0')) {
        month = '0' + month
      }
      if (day < 10&& !day.toString().includes('0') ) {
        day = '0' + day
      }
    return date.getFullYear() + '-' + month + '-' + day+' '+"23"+':'+'59'+':'+'59';

  },
    timeFormat (date) {
      if (!date || typeof(date) === "string") {
        this.error("参数异常，请检查...");
      }
      let yy = date.getFullYear(); //年
      let mm = date.getMonth() + 1; //月
      let dd = date.getDate(); //日
      if (mm < 10&& !mm.toString().includes('0')) {
        mm = '0' + mm
      }
      if (dd < 10&& !dd.toString().includes('0') ) {
        dd = '0' + dd
      }
      return yy+'-'+mm+'-'+dd+' '+"00"+':'+'00'+':'+'00';
    },
    timeFormatTwo (date) {
      if (!date || typeof(date) === "string") {
        this.error("参数异常，请检查...");
      }
      let yy = date.getFullYear(); //年
      let mm = date.getMonth() + 1; //月
      let dd = date.getDate(); //日
      if (mm < 10) {
        mm = '0' + mm
      }
      if (dd < 10) {
        dd = '0' + dd
      }
      return yy+'-'+mm+'-'+dd+' '+"23"+':'+'59'+':'+'59';
    },

  },
  mounted () {
    // 注意，这里要用个变量存this，不然进到getSystemInfo后this指向会变化，找不到data变量
    var _this = this
    uni.getSystemInfo({
      success: function (res) {
        _this.setHeight = res.screenHeight
      }
    })
  },
}
